{% import "macro.html.twig" as web_macro %}
<table class="table table-striped table-hover" id="order-table">
  <thead>
  <tr>
    <th width="30%">{{ 'order.product_name'|trans }}</th>
    <th>{{ 'order.status'|trans }}</th>
    <th>{{ 'order.product_price'|trans }} </th>
    <th>{{ 'order.discount_amount'|trans }}</th>
    <th>{{ 'order.price'|trans }}</th>
    <th width="10%">{{'order.buyers'|trans }}</th>
    <th>
      {{ 'order.payment_pattern'|trans }}
    </th>
    <th>
      {{'order.source'|trans}} 
      <span class="glyphicon glyphicon-question-sign color-gray text-sm" data-toggle="tooltip" data-placement="top"  title="{{ 'admin.order.tips'|trans }}"></span>
    </th>
    <th width='60'>{{'user.orders.operation'|trans}}</th>
  </tr>
  </thead>
  <tbody>
  {% for order in orders %}
    {% set buyer = users[order.user_id]|default(null) %}
    <tr id="order-table-{{order.id}}" style="word-break: break-all;word-wrap: break-word;">
      <td>
        {% if order.item.target_type|default('') == 'course' %}
          <a  class="link-primary" href="{{ path('course_show', {id:order.item.target_id}) }}" target="_blank"><strong>{{order.title}}</strong></a>
        {% elseif order.item.target_type|default('') == 'vip' %}
          <a class="link-primary" href="{{ path('vip', {id:order.item.target_id}) }}" target="_blank"><strong>{{order.title}}</strong></a>
        {% elseif order.item.target_type|default('') == 'classroom' %}
          <a class="link-primary" href="{{ path('classroom_show', {id:order.item.target_id}) }}" target="_blank"><strong>{{order.title}}</strong></a>
        {% else %}
          <strong>{{order.title}}</strong>
        {% endif %}
        <br/>
        <span class="color-gray text-sm">{{'user.orders.order_id'|trans({'%sn%':order.sn})}}</span>
        <br/>
        <span class="color-gray text-sm">{{ 'order.created_time'|trans }}: {{ order.created_time|date('Y-n-d H:i:s') }}</span>
      </td>
      <td>{{ display_order_status(order.status, 1) }}</td>
      <td><span class="color-warning">{{ order.price_amount|to_cash(0) }}</span></td>
      <td><span class="color-warning">{{ (order.price_amount - order.pay_amount)|to_cash(0) }}</span></td>
      <td><span class="color-warning">{{order.pay_amount|to_cash(0) }}</span></td>
      {% if has_permission('admin_user_manage') %}
        <td>
          <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_user_show', {id:buyer.id}) }}">{{ buyer.nickname|default('--') }}</a>
        </td>
      {% else %}
        <td>
          <span><a target="_blank" href="{{ path('user_show', {id: buyer.id}) }}">{{ buyer.nickname|default('--') }}</a></span>
        </td>
      {% endif %}
      <td>{{ dict_text('payment',order.payment) }}</td>
      <td>{{ dict_text('source', order.source) }}</td>
      <td>
        <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_order_detail', {id:order.id}) }}">{{'form.btn.detail'|trans}}</a>

        {% if order.status == 'created' or order.status == 'paying' %}
          <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_order_adjust_price', {id:order.id}) }}">{{ 'order.adjust_price_btn'|trans }}</a>
        {% endif %}

      </td>
    </tr>
  {% else %}
    <tr><td colspan="20"><div class="empty">{{'site.datagrid.empty'|trans}}</div></td></tr>
  {% endfor %}
  </tbody>
</table>
<div class="paginator">
  {{ admin_macro.paginator(paginator) }}
</div>
